﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using SmartSpace.Core;
using SmartSpace.Workflow;

namespace SsTool.Common
{
    /// <summary>
    /// Interaction logic for SelectActivityWindow.xaml
    /// </summary>
    public partial class SelectActivityWindow : Window
    {
        public ActivityMetadata SelectedActivity { get; private set; }

        public SelectActivityWindow()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(SelectActivityWindow_Loaded);
        }

        void SelectActivityWindow_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void LoadDatas()
        {
            IWorkflowService service = App.Get<IWorkflowService>();
            this._ctlGridWorkflows.ItemsSource = service.FindWorkflows(0, 999);
        }

        private void _ctlGridWorkflows_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            WorkflowMetadata selectedWorkflow = _ctlGridWorkflows.SelectedItem as WorkflowMetadata;
            if (selectedWorkflow != null)
            {
                _ctlGridActivities.ItemsSource = selectedWorkflow.Activities;
            }
        }

        private void _ctlBtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedActivity = _ctlGridActivities.SelectedItem as ActivityMetadata;
            if (SelectedActivity != null)
            {
                DialogResult = true;
            }
        }
    }
}
